##import requests

####response = requests.get('https://www.amazon.co.jp/')
####print(response.status_code)  # 打印状态码
####print(response.url)          # 打印请求url
####print(response.headers)      # 打印头信息
####print(response.cookies)      # 打印cookie信息
####print(response.text)  #以文本形式打印网页源码
####print(response.content) #以字节流形式打印
####
####
import requests
from lxml import etree
from requests.adapters import HTTPAdapter
s = requests.session()

# max_retries=3 重试3次
s.mount('http://',HTTPAdapter(max_retries=3))
s.mount('https://', HTTPAdapter(max_retries=3))

f=open("rbmrt.txt","a",encoding="utf-8")
url = "https://www.amazon.co.jp/hz/leaderboard/hall-of-fame"
r = s.request("GET", url=url, timeout=15)
r.encoding = r.apparent_encoding
print(r.text)
html = etree.HTML(r.text)
result = html.xpath('//tr/td[2]/a[1]/@href')
print(len(result))
for line in result:
    f.write('https://www.amazon.co.jp'+line+'\n')
    print('https://www.amazon.co.jp'+line+'\n')
f.close()
